package promogui;

import java.util.ArrayList;
import java.util.Iterator;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.category.BarRenderer;
import org.jfree.chart.urls.StandardCategoryURLGenerator;
import org.jfree.data.category.DefaultCategoryDataset;


public class ProjectsOverviewChart
{
    private JFreeChart chart;
    private DefaultCategoryDataset dataset;
    
    public ProjectsOverviewChart(ArrayList<Project> projects)
    {
        createDataset(projects);
        createChart("");
    }
    
    public JFreeChart getChart()
    {
        return chart;
    }
    
    private void createChart(String title) 
    {
       
        chart = ChartFactory.createBarChart3D(
        	title, 
        	"",
        	"",
        	dataset, 
        	PlotOrientation.HORIZONTAL, 
            false,                   // include legend
            true,
            true
        ); 
        
        

        
        final CategoryPlot plot = chart.getCategoryPlot();
        
        plot.setRenderer(new ProjectsOverviewBarRenderer());
    }
    
    private  void createDataset(ArrayList<Project> projects)
    {
    	dataset = new DefaultCategoryDataset();

		// row keys...
		String series1 = "Prozent";
		
		Iterator<Project> it = projects.iterator();
		
		while(it.hasNext())
		{
			Project project = it.next();
			dataset.addValue(project.getWorkedPercent(), series1, project.getName());	
		}
    }
}
